<?php
/**
 * Created by PhpStorm.
 * User: Liulibao
 * Date: 2019/10/11
 * Time: 18:43
 */

namespace app\common\model;

use think\Model;



class AfficheTypeModel extends Model
{
    protected $table = 'ds_affiche_types';

    public $page_info;

    /**
     * @description: 获取公告分类列表  @MrLiu
     * @param array $condition
     * @param $page
     * @param string $order
     * @return false|\PDOStatement|string|\think\Collection
     * @internal param bool $isArray
     */
    public function getAfficheTypeList($condition = [], $page = 0, $order = 'id desc')
    {
        $result = $this;

        if (!is_array($condition)) {
            $result = $result->where($condition);
        }

        if ($page) {
            $result = $result->order($order)->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $result;
            return $result->items();
        } else {
            return $result->order($order)->limit(10)->select();
        }
    }

    /**
     * @description: 获取某一条数据  @MrLiu
     * @param $id
     * @return array|bool|false|\PDOStatement|string|Model
     */
    public function getOneAfficheTypeById($id)
    {
        if (intval($id) <= 0) {
            return false;
        }

        return $this->where(array('id' => $id))->find();
    }

    /**
     * @description: 根据条件查询获取某一条数据 @MrLiu
     * @param array $condition
     * @return array|bool|false|\PDOStatement|string|Model
     */
    public function getOneAfficheType($condition = [])
    {
        if (empty($condition)) {
            return false;
        }

        return $this->where($condition)->find();
    }

    /**
     * @description: 新增数据  @MrLiu
     * @param $data
     * @return int|string
     */
    public function addAfficheType($data)
    {
        return $this->insertGetId($data);
    }

    /**
     * @description: 更新信息  @MrLiu
     * @param $data
     * @param $ac_id
     * @return $this
     */
    public function editAfficheType($data,$id)
    {
        return $this->where('id',$id)->update($data);
    }

    /**
     * @description: 删除分类  @MrLiu
     * @param $id
     * @return int
     */
    public function delAfficheType($id)
    {
        $is_exit = model('afficheModel')->getOneAffiche(array('typeid' => $id));
        if (!empty($is_exit)) {
            return false;
        }
        return $this->where('id', $id)->delete();

    }
}